package com.unione.unione_network.tcp_socket

import android.util.Log
import java.io.IOException
import java.io.InputStream

/**
 * 最简单的做法，不处理粘包，直接读取返回，最大长度256
 */
class BaseStickPackageHelper(private var maxLen: Int = 1024) : AbsStickPackageHelper {

    companion object{
        const val TAG="BaseStickPackageHelper"
    }

    override fun execute(inputStream: InputStream): ByteArray? {
        val bytes = ByteArray(maxLen)
        var len: Int
        try {
            if (inputStream.read(bytes).also { len = it } != -1) {
                Log.d(TAG,String(bytes))
                return bytes.copyOf(len)
            }
        } catch (e: IOException) {
//           e.printStackTrace();
        }
        return null
    }
}